package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.vo.DeviceDataVo;
import com.zzyl.nursing.vo.DeviceDetailVo;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 设备类型Controller
 * 
 * @author 大黑牛
 * @date 2025-10-17
 */
@RestController
@RequestMapping("/nursing/device")
@Api(tags = "设备类型的接口")
public class DeviceController extends BaseController
{
    @Autowired
    private IDeviceService deviceService;

    /**
     * 查询设备类型列表
     */
    @ApiOperation("查询设备类型列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(Device device)
    {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

    /**
     * 物联网平台同步产品列表
     */
    @ApiOperation("查询设备类型列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @PostMapping("/syncProductList")
    public AjaxResult syncProductList()
    {
        deviceService.syncProductList();
        return AjaxResult.success();
    }

    /**
     * 查询所有产品列表
     */
    @ApiOperation("查询所有产品列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/allProduct")
    public AjaxResult allProduct()
    {
        List<ProductVo> productVo =   deviceService.allProduct();
        return AjaxResult.success(productVo);
    }

/**
 *  新增
 */
@ApiOperation("分页查询设备列表")
@PostMapping("/register")
public AjaxResult register(@RequestBody DeviceDto dto)
{
    deviceService.register(dto);
    return AjaxResult.success();
}

    /**
     *  查询设备详细数据
     */
    @ApiOperation("查询设备详细数据")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/{iotId}")
    public AjaxResult getIotId(@PathVariable String iotId)
    {
        DeviceDetailVo deviceDetailVo =  deviceService.getIotId(iotId);
        return AjaxResult.success(deviceDetailVo);
    }


    /**
     *  查询设备影子数据（设备的属性）
     */
    @ApiOperation("查询设备影子数据（设备的属性）")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/queryServiceProperties/{iotId}")
    public AjaxResult queryServiceProperties(@PathVariable String iotId)
    {
        List<DeviceDataVo> deviceDataVo =  deviceService.queryServiceProperties(iotId);
        return AjaxResult.success(deviceDataVo);
    }


    /**
     *  修改设备
     */
    @ApiOperation("修改设备")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @PutMapping
    public AjaxResult queryServiceProperties(@RequestBody DeviceDto dto)
    {
        deviceService.updateDevice(dto);
        return AjaxResult.success();
    }




    /**
     *  删除设备
     */
    @ApiOperation("删除设备")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @DeleteMapping("/{iotId}")
    public AjaxResult deleteDevice(@PathVariable String iotId)
    {
        deviceService.deleteDevice(iotId);
        return AjaxResult.success();
    }


/*    请求 URL
    http://localhost:8001/dev-api/nursing/device/queryProduct/68f1b0740a9ab42ae58568af
    请求方法
            GET
    状态代码
404 Not Found
    远程地址
[::1]:8001
    引用站点策略
    strict-origin-when-cross-origin*/
    /**
     * 心率报警规则
     */
    @ApiOperation("心率报警规则")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("queryProduct/{productKey}")
    public AjaxResult queryProduct(@PathVariable String productKey)
    {
        return deviceService.queryProduct(productKey);
    }


}
